<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Arenacontest extends Model
{
    protected $table = 'arenacontest';

    public function organizerUser()
    {
        return $this->belongsTo('App\Models\WechatUser', 'organizer');
    }

    public function signup()
    {
        return $this->hasMany('App\Models\ArenacontestUser');
    }

    public function cityInfo()
    {
        return $this->belongsTo('App\Models\CityList', 'city', 'key');
    }

    public function status($status = null)
    {
        $arr = [
            0 => "取消",
            10 => "等待审核",
            20 => "审核通过",
            30 => "比赛完成",
        ];
        if ($status !== null) {
            return array_key_exists($status, $arr) ? $arr[$status] : $arr['0'];
        }else{
            return $arr['2'];
        }
        return $arr;
    }

    public function cityInfoByKey($key)
    {
        $city = CityList::where('key', $key)->first();
        return $city;
    }

    public static function getArenacontestList()
    {
        $array = Arenacontest::selectRaw("`id` ,`title`")
            ->pluck('title', 'id')
            ->toArray();
        return $array;
    }
}
